package com.anket;

import javax.faces.event.PhaseEvent;
import javax.faces.event.PhaseId;
import javax.faces.event.PhaseListener;

import org.hibernate.SessionFactory;

import com.hibernate.util.HibernateUtil;

public class RestoreViewPhaseListener implements PhaseListener {

	
	public void afterPhase(PhaseEvent arg0) {
//		SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
//		try {
//			sessionFactory.getCurrentSession().getTransaction().commit();
//		} catch (Throwable ex) {
//
//			// very bad error here, occured...
//			if (sessionFactory.getCurrentSession().getTransaction().isActive()) {
//				sessionFactory.getCurrentSession().getTransaction().rollback();
//			}
//		}

	}

	
	public void beforePhase(PhaseEvent arg0) {
		SessionFactory sessionFactory = null;
		sessionFactory = HibernateUtil.getSessionFactory();
		sessionFactory.getCurrentSession().beginTransaction();

	}

	
	public PhaseId getPhaseId() {
		// TODO Auto-generated method stub
		return PhaseId.RESTORE_VIEW;
	}

}
